package com.ljx.rabbit.controller;


import com.ljx.rabbit.domain.dto.GoodsPageDTO;
import com.ljx.rabbit.domain.po.HeadGoods;
import com.ljx.rabbit.domain.vo.CategoryDetail;
import com.ljx.rabbit.domain.vo.CategoryFilter;
import com.ljx.rabbit.domain.vo.GoodsPageVo;
import com.ljx.rabbit.domain.vo.HomeGoods;
import com.ljx.rabbit.result.R;
import com.ljx.rabbit.service.ICategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-21
 */
@RestController
@RequestMapping("/category")
@Api(tags = "分类")
@RequiredArgsConstructor
@Slf4j
@CrossOrigin
public class CategoryController {
    private final ICategoryService categoryService;
    @ApiOperation(value = "获取二级分类")
    @GetMapping
    public R<CategoryDetail> getCategory(@RequestParam("id") Long id) {
        log.info("getCategory id:{}", id);
        if (id ==  null) throw new RuntimeException("id不能为空");
        CategoryDetail categoryDetail = categoryService.getCategoryAndGoods(id);
        return R.success(categoryDetail);
    }

    @ApiOperation(value = "获取2级分类的面包屑")
    @GetMapping("/sub/filter")
    public R<CategoryFilter> getCategoryFilter(@RequestParam("id") Long id) {
        log.info("getCategoryFilter id:{}", id);
        if (id ==  null) throw new RuntimeException("id不能为空");
        CategoryFilter categoryFilter = categoryService.getCategoryFilter(id);
        return R.success(categoryFilter);
    }

    @ApiOperation(value = "获取2级分类下的全部商品")//由于商品太少，就直接获取全部商品
    @PostMapping("/goods/temporary")
    public R<GoodsPageVo> getGoodsPage(@RequestBody GoodsPageDTO goodsPageDTO) {
        log.info("getGoodsPage goodsPageDTO:{}", goodsPageDTO);
        if (goodsPageDTO ==  null) throw new RuntimeException("参数不能为空");
        GoodsPageVo goodsPageVo = categoryService.getGoodsPage(goodsPageDTO);
        return R.success(goodsPageVo);
    }
}
